Skip to content

✨Map scf.for operations by restoration using the 4-approximation token swap algorithm#1805

Draft
MatthiasReumann wants to merge 34 commits into
mainfrom
enh/sc-map-scf-for-loops
Draft

✨Map scf.for operations by restoration using the 4-approximation token swap algorithm#1805
MatthiasReumann wants to merge 34 commits into
mainfrom
enh/sc-map-scf-for-loops

Conversation

@MatthiasReumann

Copy link
Copy Markdown
Collaborator

Changes

  • ✨Add functionality to handle operation with nested operations.
  • ✨ Implement the 4-Approximation Algorithm described in arXiv:1602.05150v3.
  • ✨Add two unit tests for quantum programs using scf.for operations and one unrolling unit test.
  • 📝 Use LLVM codebase style function description (consistent with the IRVerifier and some other parts of the cc).
  • 🚛 Move Layout class to separate file.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • I have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@MatthiasReumann MatthiasReumann self-assigned this Jun 23, 2026
@MatthiasReumann MatthiasReumann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Jun 23, 2026
@MatthiasReumann MatthiasReumann added this to the MLIR Support milestone Jun 23, 2026
@mergify mergify Bot added the conflict label Jun 23, 2026
@mergify mergify Bot removed the conflict label Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-tidy (v22.1.8) reports: 18 concern(s)
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp:23:1: warning: [misc-include-cleaner]

    included header ArrayRef.h is not used directly

       23 | #include <llvm/ADT/ArrayRef.h>
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       24 | #include <llvm/ADT/PriorityQueue.h>
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp:38:1: warning: [misc-include-cleaner]

    included header IRMapping.h is not used directly

       38 | #include <mlir/IR/IRMapping.h>
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       39 | #include <mlir/IR/Location.h>
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp:337:5: warning: [misc-include-cleaner]

    no header providing "mlir::OpBuilder" is directly included

       35 |     OpBuilder::InsertionGuard guard(rewriter);
          |     ^
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp:13:1: warning: [misc-include-cleaner]

    included header ArrayRef.h is not used directly

       13 | #include <llvm/ADT/ArrayRef.h>
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       14 | #include <llvm/ADT/STLExtras.h>
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp:22:29: warning: [misc-include-cleaner]

    no header providing "size_t" is directly included

       18 | #include <numeric>
       19 | #include <random>
       20 | 
       21 | namespace mlir::qco {
       22 | Layout Layout::random(const size_t nqubits, const size_t seed) {
          |                             ^
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp:25:16: warning: [misc-include-cleaner]

    no header providing "std::ranges::shuffle" is directly included

       18 | #include <numeric>
       19 | #include <random>
       20 | 
       21 | namespace mlir::qco {
       22 | Layout Layout::random(const size_t nqubits, const size_t seed) {
       23 |   SmallVector<size_t> mapping(nqubits);
       24 |   std::iota(mapping.begin(), mapping.end(), size_t{0});
       25 |   std::ranges::shuffle(mapping, std::mt19937_64{seed});
          |                ^
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp:36:3: warning: [misc-include-cleaner]

    no header providing "assert" is directly included

       18 |   assert(prog < programToHardware_.size() && "program index out of bounds");
          |   ^
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp:56:8: warning: [misc-include-cleaner]

    no header providing "std::swap" is directly included

       20 |   std::swap(hardwareToProgram_[hwA], hardwareToProgram_[hwB]);
          |        ^
  • mlir/lib/Dialect/QCO/Utils/WireIterator.cpp:71:27: warning: [misc-include-cleaner]

    no header providing "llvm::find" is directly included

       17 |           auto it = llvm::find(op.getQubits(), qubit_);
          |                           ^
  • mlir/lib/Dialect/QCO/Utils/WireIterator.cpp:128:27: warning: [misc-include-cleaner]

    no header providing "llvm::find" is directly included

      128 |           auto it = llvm::find(op.getResults(), res);
          |                           ^
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:31:1: warning: [misc-include-cleaner]

    included header WalkResult.h is not used directly

       31 | #include <mlir/Support/WalkResult.h>
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       32 | #include <mlir/Transforms/Passes.h>
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:44:8: warning: [misc-use-internal-linkage]

    struct 'Device' can be moved into an anonymous namespace to enforce internal linkage

       44 | struct Device {
          |        ^
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:61:22: warning: [misc-include-cleaner]

    no header providing "llvm::zip_equal" is directly included

       18 |                llvm::zip_equal(op.getInputQubits(), op.getOutputQubits())) {
          |                      ^
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:66:15: warning: [misc-include-cleaner]

    no header providing "mlir::qco::UnitaryOpInterface" is directly included

       13 |         .Case<UnitaryOpInterface>([&](UnitaryOpInterface& op) {
          |               ^
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:89:22: warning: [misc-include-cleaner]

    no header providing "llvm::zip_equal" is directly included

       89 |                llvm::zip_equal(op.getInits(), op.getRegionIterArgs())) {
          |                      ^
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp:107:22: warning: [misc-include-cleaner]

    no header providing "llvm::zip_equal" is directly included

      107 |                llvm::zip_equal(op.getRegionIterArgs(), op.getYieldedValues())) {
          |                      ^
  • mlir/unittests/Dialect/QCO/Utils/test_wireiterator.cpp:16:1: warning: [misc-include-cleaner]

    included header Debug.h is not used directly

       16 | #include <llvm/Support/Debug.h>
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       17 | #include <mlir/Dialect/Arith/IR/Arith.h>
  • mlir/unittests/Dialect/QCO/Utils/test_wireiterator.cpp:73:16: warning: [misc-include-cleaner]

    no header providing "mlir::SmallVector" is directly included

       22 |         return SmallVector{iterQ02, iterQ11};
          |                ^

Have any feedback or feature suggestions? Share it here.

@mergify mergify Bot added the conflict label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code conflict enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant